<template>
  <div>
    <el-dialog title="角色管理" :visible="showDialog" @close="batnce">
      <el-checkbox-group v-model="checkList">
        <el-checkbox
          v-for="item in rlosList"
          :key="item.id"
          :label="item.id"
        >
          {{ item.name }}
        </el-checkbox>

      </el-checkbox-group>
      <template #footer>
        <el-row type="flex" justify="center">
          <el-button size="small" type="primary" @click="isOk">确认</el-button>
          <el-button size="small" @click="batnce">取消</el-button>
        </el-row>
      </template>

    </el-dialog>
  </div>
</template>

<script>
import { getRoleList } from '@/api/setting'
import { getUserDetailById } from '@/api/user'
import { assignRoles } from '@/api/employees'
export default {
  components: {

  },
  props: {
    showDialog: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      checkList: [],
      rlosList: [],
      userId: ''
    }
  },
  computed: {

  },
  watch: {

  },
  async created() {
    const { rows } = await getRoleList()
    // console.log(rows)
    this.rlosList = rows
  },
  mounted() {

  },
  methods: {
    async isOk() { // 保存修改
      await assignRoles({ roleIds: this.checkList, id: this.userId })
      this.$message.success('操作成功')
      this.$emit('update:showDialog', false)
    },
    batnce() {
      this.$emit('update:showDialog', false)
    },
    async  getUserDetailById(id) {
      this.userId = id
      const { roleIds } = await getUserDetailById(id)// 数据回显
      this.checkList = roleIds
      // console.log(this.checkList)
    }
  }
}
</script>

<style scoped lang="less">

</style>
